<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="css/mui.css" rel="stylesheet" />
		<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.min.js"></script>
		<script src="js/mui.js"></script>
		<script src="./utils/myRequest.js"></script>
		<script type="text/javascript">
			mui.init();
			mui.plusReady(function () {
				var user = store.getItem();
			    request.ajax({
			    	url : "/websocket/t-friend-apply/allFriendApply",
			    	data : {
						id : user.id
					},
			    	type : "post",
			    	success : function(resp){
			    		if(resp.code == 20000){
			    			//获取ul对象
							var ul = document.getElementById("ul");
			    			var arrays = resp.data.list;
			    			
			    			for (var i = 0; i < arrays.length; i++) {
			    				var html = "";
								html += "<li class=\"mui-table-view-cell mui-media\">\n";
								        html += "<a href=\"javascript:;\">\n";
								        html += "<img class=\"mui-media-object mui-pull-left\" style=\"border-radius: 50%;\" src=\""+arrays[i].tuser.minHeand+"\">\n";
								        html += "<div class=\"mui-media-body\">\n";
								        html += "<p class=\"mui-ellipsis\">"+arrays[i].tuser.username+"</p>\n";
								        html += "<p class=\"mui-ellipsis\">"+arrays[i].tuser.nickname+"</p>\n";
								        html += "</div>\n";
								        html += "</a>\n";
										if(arrays[i].status == 1){
											html += "<button id=\""+arrays[i].id+"\" num=\"2\" type=\"button\" class=\"mui-btn mui-btn-success success\" style=\"margin-right: 60px;\">同意</button>\n";
											html += "<button id=\""+arrays[i].id+"\" num=\"3\" type=\"button\" class=\"mui-btn mui-btn-danger danger\">拒绝</button>\n";
										}else if(arrays[i].status == 2){
											html += "<button disabled=\"disabled\" type=\"button\" class=\"mui-btn mui-btn-success\">已同意</button>\n";
										}else if(arrays[i].status == 3){
											html += "<button disabled=\"disabled\" type=\"button\" class=\"mui-btn mui-btn-danger\">已拒绝</button>\n";
										}
								       
								        html += "</li>";
											  
								$("#ul").append(html);
			    			}
			    			
			    		}
			    	}
			    	
			    });
			
				mui(".mui-table-view").on('tap','.success',function(){
					  //获取id
					 var friendPlayId = this.getAttribute("id");
					 var status = this.getAttribute("num");
					 console.log(friendPlayId + ":" + status);
					 // plus.nativeUI.toast(friendPlayId + ":" + status);
					 //跳转到好友认证页面
					 mui.openWindow({
						 url:'newAuth.html',
						 id:'newAuth.html',
						 extras:{
							   friendPlayId : friendPlayId,
							   status : status
						 }
					 });
				});
				
				mui(".mui-table-view").on('tap','.danger',function(){
					  //获取id
					 var friendPlayId = this.getAttribute("id");
					 var status = this.getAttribute("num");
					 console.log(friendPlayId + ":" + status);
					 // plus.nativeUI.toast(friendPlayId + ":" + status);
					 var param = new Object();
					 param.friendPlayId = friendPlayId;
					 param.status = status;
					 request.ajax({
						 url : "/websocket/t-friend-apply/isStatus",
						 data : param,
						 type : "post",
						 success : function(resp){
							 console.log(typeof resp);
							 if(resp.code == 20000){
								 plus.nativeUI.toast(resp.message);
								 //刷新页面
								 location.reload(true);
							 }else{
								 plus.nativeUI.toast(resp.message);
							 }
						 }
					 })
				}) 
				
			});
		</script>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">好友通知</h1>
		</header>
		
		<div style="margin-top: 50px;">
			<ul class="mui-table-view" id="ul">
				<!-- <li class="mui-table-view-cell mui-media">
					<a href="javascript:;">
						<img class="mui-media-object mui-pull-left" style="border-radius: 50%;" src="img/tou.jpg">
						<div class="mui-media-body">
							<p class="mui-ellipsis">486566947</p>
							<p class="mui-ellipsis">未进化的程序猿</p>
						</div>
					</a>
					<button disabled="disabled" type="button" class="mui-btn mui-btn-success" style="margin-right: 60px;">同意</button>
					<button type="button" class="mui-btn mui-btn-danger">拒绝</button>
				</li> -->
				
			</ul>
		</div>
	</body>

</html>
